package com.jf.identity.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 读取 .properties 文件
 *
 * @author FCG
 */
public class PropertiesUtil {
    private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
    private static Properties properties = new Properties();
    private static String fileName = "appConfig.properties";

    static {
        try (InputStream is = PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName)) {
            properties.load(is);
        } catch (IOException e) {
            logger.error("读取" + fileName + "文件失败", e);
        }
    }

    public static String getProperty(String key) {
        if (StringUtils.isEmpty(key)) {
            return null;
        }
        return properties.getProperty(key);
    }
}
